﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{/*
  * 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.

  * 
  * 
  * */

    class Problem34
    {
        public static string Calculate()
        {
            int sum = 0;
            for (int i = 3; i < 9999999; i++)
            {
                if (NumberEqualsFactorielSum(i))
                {
                    Console.WriteLine(i);
                    sum += i;
                }
            }

            return sum.ToString();
        }

        static bool NumberEqualsFactorielSum(int n)
        {
            var digits = CommonFunctions.GetDigits(n);
            int sum = 0;
            foreach (int digit in digits)
            {
                sum += (int)CommonFunctions.Factoriel(digit);
            }

            return n == sum;
        }
    }
}
